import { ApiTags, ApiOperation, ApiQuery} from "@nestjs/swagger";
import { Controller, Get, Put, Body, Delete, Post, Param } from "@nestjs/common";
import { BlogService } from "./blog.service";
import { BlogDto } from "./blog.dto";


@ApiTags('博客')
@Controller('blog')
export class BlogController{
    constructor(
        private readonly blogService:BlogService
    ){}
    /**
     * 后端分页
     * @param page 
     */
    // @Get()
    // @ApiOperation({summary:'查询所有博客'})
    // @ApiQuery({ type: 'number', name: 'page', required: false ,description:'当前页数'})
    // @ApiQuery({ type: 'number', name: 'pagesize', required: false ,description:'每页条数（当其中一个无值将返回所有数据）'})
    // async find(@Param() page:{ page: number, pagesize: number }){
    //     return await this.blogService.findAllBlog(page);
    // }
    @Get()
    @ApiOperation({summary:'查询所有博客'})
    async find(){
        return await this.blogService.findAllBlog();
    }

    @Put()
    @ApiOperation({summary:'新增博客'})
    async add(@Body() blog:BlogDto){
        return await this.blogService.add(blog);
    }
    @Delete()
    @ApiOperation({summary:'根据id，或者ids删除博客'})
    @ApiQuery({ name: 'id',type:'number'})
    @ApiQuery({ name: 'ids',type:'[number]'})
    async remove(@Body() {id,ids}){
        return await this.blogService.remove(id||ids)
    }

    @Post()
    @ApiOperation({summary:'更改博客'})
    async update(@Body() blog:BlogDto){
        //module.update()报错，只能使用save，功能能够实现，效率稍微低下
        return await this.blogService.add(blog);
    }

}